package com.example.jh352160.surfingtv.thematic_details.customView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.jh352160.surfingtv.R;

/**
 * Created by jh352160 on 2016/7/29
 */

public class Share_page extends RelativeLayout implements View.OnClickListener {

    Context context;
    ImageView back, qq, weixin, weibo, friendCircle;
    View share_page;

    public Share_page(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    public Share_page(Context context) {
        super(context);
        this.context = context;
        init();
    }

    private void init() {
        LayoutInflater.from(context).inflate(R.layout.thematic_share_button, this);
        back = (ImageView) findViewById(R.id.back);
        qq = (ImageView) findViewById(R.id.qq);
        weixin = (ImageView) findViewById(R.id.weixin);
        weibo = (ImageView) findViewById(R.id.weibo);
        share_page = findViewById(R.id.share_view);
        friendCircle = (ImageView) findViewById(R.id.friendCircle);

        qq.setOnClickListener(this);
        weixin.setOnClickListener(this);
        weibo.setOnClickListener(this);
        friendCircle.setOnClickListener(this);

        share_page.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                stopAnim();
            }
        });
    }

    public void startAnim() {
        Animation anim1 = AnimationUtils.loadAnimation(context, R.anim.share1);
        Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.share2);
        Animation anim3 = AnimationUtils.loadAnimation(context, R.anim.share3);
        Animation anim4 = AnimationUtils.loadAnimation(context, R.anim.share4);
        weibo.startAnimation(anim1);
        weixin.startAnimation(anim2);
        friendCircle.startAnimation(anim3);
        qq.startAnimation(anim4);
    }

    public void stopAnim() {
        Animation anim1 = AnimationUtils.loadAnimation(context, R.anim.share_back1);
        Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.share_back2);
        Animation anim3 = AnimationUtils.loadAnimation(context, R.anim.share_back3);
        Animation anim4 = AnimationUtils.loadAnimation(context, R.anim.share_back4);
        weibo.startAnimation(anim1);
        weixin.startAnimation(anim2);
        friendCircle.startAnimation(anim3);
        qq.startAnimation(anim4);
        anim1.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Share_page.this.setVisibility(GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.qq:

                break;
            case R.id.weixin:

                break;
            case R.id.weibo:

                break;
            case R.id.friendCircle:

                break;
        }
    }
}
